package com.burgeon.backend.SHOPBACKEND.rest.weixin;
/**
 * 创建标签
 */
import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.vip.Employee;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class InsertVip extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public InsertVip(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String phone, String name, String sex, String birth, Employee data, String openId) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(phone,name,sex,birth,data,openId), url);

        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message= new JSONArray(str).getJSONObject(0).getString("message");

        if (!"0".equals(code)) {
            throw new Exception("创建失败"+message);
        }
        return code;
    }

    private MultiValueMap Data(String phone,String name, String sex, String birth,Employee data,String openId) {

        HashMap params = new HashMap();

        params.put("c_vip_id__cardno",phone);
        params.put("C_VIPTYPE_ID__NAME","普通卡");	//VIP类型
        params.put("C_CUSTOMER_ID__NAME",data.getcCustomerId());//	经销商
        params.put("C_STORE_ID__NAME",data.getcStoreId());	//开卡店仓
        params.put("MOBIL",phone);//	手机
        params.put("VIPNAME",name);//	顾客姓名
        params.put("SEX",sex);	//性别
        params.put("BIRTHDAY",birth);//生日OPENID	Openid
        params.put("OPENID",openId);
        params.put("HR_EMPLOYEE_ID1__NAME",data.getName());//HR_EMPLOYEE_ID__NAME	开卡人
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateString = sdf.format(now);
        params.put("CARDNO",phone);//卡号

        params.put("OPENCARDDATE",dateString);

        params.put("table", "C_VIP");//表名

        return DATA("ObjectCreate", params, account, password);
    }

    public static void main(String[] args) {
        InsertVip g = new InsertVip("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
//            VipAttrib vipAttrib = new VipAttrib();
//            vipAttrib.setVipAttrib2("120-140");
//            g.getData("17732145129",vipAttrib);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
